<?php
	class laisuatguidb
	{
		public function Them($MaLoaiKyHan = 0, $PhanTramLaiSuatGui = 0, $HangThang = 0, $HangNam = 0, $NgayCapNhat = "")
		{
			$sql = "INSERT INTO laisuatgui(MaLoaiKyHan, PhanTramLaiSuatGui, HangThang, HangNam, NgayCapNhat)
					VALUES($MaLoaiKyHan, $PhanTramLaiSuatGui, $HangThang, $HangNam, '$NgayCapNhat')";

			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function TonTaiTrongSoTietKiem($MaLaiSuatGui = 0)
		{
			$sql = "SELECT * FROM sotietkiem WHERE 1";
			if($MaLaiSuatGui > 0)
				$sql.= " AND MaLaiSuatGui = $MaLaiSuatGui";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function CapNhat($MaLaiSuatGui = 0, $MaLoaiKyHan = 0, $PhanTramLaiSuatGui = 0, $HangThang = 0, $HangNam = 0)
		{
			$sql = "UPDATE laisuatgui 
					SET MaLoaiKyHan = $MaLoaiKyHan,
						PhanTramLaiSuatGui = $PhanTramLaiSuatGui,
						HangThang = $HangThang,
						HangNam = $HangNam 
					WHERE MaLaiSuatGui = $MaLaiSuatGui";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Xoa($MaLaiSuatGui = 0)
		{
			$sql = "DELETE FROM laisuatgui 
					WHERE MaLaiSuatGui = $MaLaiSuatGui";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function XoaTatCa()
		{
			$sql = "DELETE FROM laisuatgui";			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaLaiSuatGui = 0, $MaLoaiKyHan = 0, $PhanTramLaiSuatGui = 0, $HangThang = 0, $HangNam = 0, $NgayCapNhat = "")
		{
			$sql = "SELECT * 
					FROM laisuatgui 
					WHERE 1";
			
			if($MaLaiSuatGui > 0)
				$sql .= " AND MaLaiSuatGui = $MaLaiSuatGui";
			
			if($MaLoaiKyHan > 0)
				$sql .= " AND MaLoaiKyHan = $MaLoaiKyHan";
			
			if($PhanTramLaiSuatGui > 0)
				$sql .= " AND PhanTramLaiSuatGui = $PhanTramLaiSuatGui";
			
			if($HangThang > 0)
				$sql .= " AND HangThang = $HangThang";
			
			if($HangNam > 0)
				$sql .= " AND HangNam = $HangNam";
			
			if($NgayCapNhat != "")
				$sql .= " AND NgayCapNhat = '$NgayCapNhat'";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function CapNhatHangThang($MaLaiSuatGui=0, $HangThang = 0, $NgayCapNhat="")
		{
			$sql = "UPDATE laisuatgui 
					SET HangThang = $HangThang,
						NgayCapNhat = '$NgayCapNhat'
					WHERE MaLaiSuatGui = $MaLaiSuatGui";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function CapNhatHangNam($MaLaiSuatGui=0, $HangNam = 0, $NgayCapNhat="")
		{
			$sql = "UPDATE laisuatgui
			SET HangNam = $HangNam,
			NgayCapNhat = '$NgayCapNhat'
			WHERE MaLaiSuatGui = $MaLaiSuatGui";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
	}
?>